package org.sysdance.aplicativo.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.sysdance.aplicativo.entidade.TurmaDiaSemana;
import org.sysdance.aplicativo.excecao.ConexaoException;
import org.sysdance.aplicativo.excecao.DAOException;
import org.sysdance.aplicativo.integracao.TurmaDiaSemanaIntegracao;
import org.sysdance.aplicativo.util.ConexaoUtil;
import org.sysdance.aplicativo.util.SysDanceUtil;

public class TurmaDiaSemanaDAO implements TurmaDiaSemanaIntegracao {

	@Override
	public void inserirTurmaDiaSemana(TurmaDiaSemana turmaDiaSemana)throws DAOException {
		final StringBuilder sql = new StringBuilder();
        sql.append("INSERT INTO turma_dia_semana(id_dia_semana, id_turma) VALUES (?, ?);");
        try {
            final Connection conexao = ConexaoUtil.criarNovaConexao();
            final PreparedStatement ps = conexao.prepareStatement(sql.toString());
            ps.setInt(1, turmaDiaSemana.getIdDiaSemana());
            ps.setInt(2, turmaDiaSemana.getIdTurma());
            ps.executeUpdate();
        } catch (final ConexaoException ex) {
            SysDanceUtil.getInstancia().imprimirLog(ex);
        } catch (final SQLException sqlex) {
            SysDanceUtil.getInstancia().imprimirLog(sqlex);
        }finally{
        	try {
				ConexaoUtil.fecharConexao();
			} catch (ConexaoException e) {
				SysDanceUtil.getInstancia().imprimirLog(e);
			}
        }
	}

}
